/*******************************************************************************
 * Copyright (c) 2011 LegSem.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl-3.0.txt
 * 
 * Contributors:
 *     LegSem - initial API and implementation
 ******************************************************************************/
package com.legsem.legstar;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public abstract class LegStarMetaData {

    public static final String METADATA_FILE_NAME = "metadata.properties";
    private static final String LOAD_PROPERTIES_ERROR = "Error attempting to load " + METADATA_FILE_NAME;
    private static final String CLOSE_PROPERTIES_ERROR = "Error attempting to close " + METADATA_FILE_NAME;

    Properties metadata;

    /** Logger. */
    private final Log log = LogFactory.getLog(getClass());

    public LegStarMetaData(Class <? extends LegStarMetaData> clazz) {
        metadata = new Properties();
        InputStream inStream = null;
        try {
            inStream = clazz.getResourceAsStream(METADATA_FILE_NAME);
            metadata.load(inStream);
        } catch (IOException e) {
            log.warn(LOAD_PROPERTIES_ERROR, e);
        } finally {
            try {
                if (inStream != null) {
                    inStream.close();
                }
            } catch (IOException e) {
                log.warn(CLOSE_PROPERTIES_ERROR, e);
            }
        }
    }

    public Properties getMetadata() {
        return metadata;
    }
}
